import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { NoviceGiftItemRenderer } from "../../novice/NoviceGiftItemRenderer";
import { ScrollPolicy } from "../../../../../flashx/textLayout/container/ScrollPolicy";
import { Cache } from "../../../cache/Cache";
import { GiftBagConfig } from "../../../resource/GiftBagConfig";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { RandomGiftBagConfig } from "../../../resource/RandomGiftBagConfig";
import { GiftBagInfo } from "../../../model/GiftBagInfo";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class ItemListPanel
    
    export  class ItemListPanel /* flash.display.Sprite */
    {
        constructor(arg1: Boolean=true)
        {
            
            this._itemShow = [];
            this.init(arg1);
            return;
        }

        /* internal  */init(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._bg = ObjCreate.createBg(0, 0, 490, 47, this, ImagesConst.RemainningTimeBg);
            }
            this._tileList = new GTileList();
            this._tileList.columnWidth = 38;
            this._tileList.rowHeight = 38;
            this._tileList.columnCount = 10;
            this._tileList.rowCount = 1;
            this._tileList.horizontalGap = 5;
            this._tileList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._tileList.setStyle("cellRenderer", NoviceGiftItemRenderer);
            this._tileList.setSize(430, 40);
            this._tileList.move(30, 5);
            this._tileList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._tileList.verticalScrollPolicy = ScrollPolicy.OFF;
            addChild(this._tileList);
            return;
        }

        public updateRewardList(arg1: int): void
        {
            var loc3=null;
            var loc1=Cache.instance.role.entityInfo.career;
            var loc2=GiftBagConfig.instance.getInfoByType(arg1);
            this._itemShow = [];
            var loc4=0;
            var loc5=loc2;
            for(loc3 of loc5) 
            {
                if (!(loc3 && loc3.type == 3 && (loc3.career == 0 || (loc3.career & loc1) > 0))) 
                {
                    continue;
                }
                this._itemShow.push(loc3);
            }
            this._tileList.dataProvider = new DataProvider(this._itemShow);
            this._tileList.drawNow();
            return;
        }

        public updateRandomGiftBagList(arg1: int): void
        {
            var loc1=RandomGiftBagConfig.instance.getInfoByType(arg1);
            this._tileList.dataProvider = new DataProvider(loc1);
            this._tileList.drawNow();
            return;
        }

        public updateListByInfos(arg1: Array<any>): void
        {
            this._tileList.dataProvider = new DataProvider(arg1);
            this._tileList.drawNow();
            return;
        }

        public setListPos(arg1: int, arg2: int=5): void
        {
            this._tileList.x = arg1;
            this._tileList.y = arg2;
            return;
        }

        public setBgWidth(arg1: int): void
        {
            if (this._bg) 
            {
                this._bg.width = arg1;
            }
            return;
        }

        public setBgHeight(arg1: int): void
        {
            if (this._bg) 
            {
                this._bg.height = arg1;
            }
            this._tileList.y = (arg1 - this._tileList.height) / 2;
            return;
        }

        public set listColumnCount(arg1: int)
        {
            this._tileList.columnCount = arg1;
            return;
        }

        public flyItemToBackpack(): void
        {
            var loc1=null;
            var loc5=null;
            if (this._itemShow.length <= 0) 
            {
                return;
            }
            var loc2=this._tileList.x;
            var loc3=this._tileList.y;
            var loc4=0;
            while (loc4 < this._itemShow.length) 
            {
                this._point = new Object /* flash.geom.Point */(loc2, loc3);
                loc1 = this._itemShow[loc4] as GiftBagInfo;
                loc5 = loc1.item.itemInfo.item.icon + ".jpg";
                LoaderManager.instance.load(loc5, this.onFlyImgLoadedHandler);
                loc2 = loc2 + 40;
                ++loc4;
            }
            return;
        }

        /* internal  */onFlyImgLoadedHandler(arg1: ImageInfo): void
        {
            FlyToNavbarTool.flyToBackPack(arg1.bitmapData, this.localToGlobal(this._point));
            return;
        }

        /* internal */ /* var */_tileList: GTileList;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_itemShow: Array<any>;

        /* internal */ /* var */_point: Object /* flash.geom.Point */;
    }
